//
//  ViewController.m
//  KTV滚动歌词
//
//  Created by dllo on 16/7/29.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"
#import "YMJLyricsLabel.h"

@interface ViewController ()
@property (nonatomic, strong) YMJLyricsLabel *lyricsLabel;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor brownColor];
    YMJLyricsLabel *lyricsLabel = [[YMJLyricsLabel alloc] initWithFrame:CGRectMake(100, 100,300, 50)];
    lyricsLabel.center = CGPointMake([UIScreen mainScreen].bounds.size.width / 2, 200);
    lyricsLabel.backgroundColor = [UIColor lightGrayColor];
    lyricsLabel.textLabel.textColor = [UIColor blackColor];
    [lyricsLabel setFont:[UIFont systemFontOfSize:23]];
    [lyricsLabel setText:@"弄快快快快快快快快快"];
    [lyricsLabel setTextAlignment:1];
    [self.view addSubview:lyricsLabel];
    self.lyricsLabel = lyricsLabel;
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
    button.center = self.view.center;
    button.backgroundColor = [UIColor purpleColor];
    [button setTitle:@"play" forState:0];
    [button setTitle:@"stop" forState:UIControlStateSelected];
    [button addTarget:self action:@selector(handlePlayButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}
- (void)handlePlayButtonTapped:(UIButton *)sender {
    NSArray *timeArray = @[
                           @(0),
                           @(1),
                           @(2),
                           @(3),
                           @(4)
                           ];
    NSArray *locationArray = @[
                               @(0),
                               @(0.3),
                               @(0.6),
                               @(0.9),
                               @(1)
                               ];
    sender.selected = !sender.selected;
    if (sender.selected) {
        [self.lyricsLabel startLyricsAnimationWithTimeArray:timeArray andLocatio0nArray:locationArray];
    } else {
        [self.lyricsLabel stopAnimation];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
